package com.atguigu.interview;

/**
 * @author Jungle
 * @create 2023-09-11 13:50
 */
public class Singleton {
    //1.可见性
    //2.防止重排序
    private volatile static Singleton singleton;

    private Singleton() {
    }

    /**
     * 双重检测锁
     */
    public static Singleton getSingleton() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }
}
